package net.huashitong.commCtrl;

import com.alibaba.fastjson.JSONArray;
import com.sirdc.modules.core.web.JsonBaseController;
import com.sirdc.modules.core.web.model.Message;
import com.sirdc.modules.sys.entity.SysFile;
import com.sirdc.modules.sys.service.SysFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/communal")
public class CommCtrl extends JsonBaseController {
    @Autowired
    private SysFileService fileservice;
    @Override
    protected String getView(String s) {
        return null;
    }

    //文件上传
    @ResponseBody
    @RequestMapping("/uploadBatch")
    public String uplaodfile(@RequestParam MultipartFile files) {
        String str = null;
        Message msg = new Message();
        if (files == null) {
            msg.setCode("500");
            return null;
        }
        Map<String, Object> mao = new HashMap<String, Object>();
        try {
            SysFile sysfile = new SysFile();
            fileservice.saveFile(sysfile, files);
            mao.put("sysid", sysfile.getSysId());
            msg.setCode("200");
            msg.setData(mao);
            str = JSONArray.toJSONString(msg);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return str;
    }
}
